#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
#include<queue>
#include<stack>

using namespace std;
class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        int n1 = pushed.size(), n2 = popped.size();
        stack<int> st;
        int tmp = 0;
        for (auto& ch : pushed)
        {
            if (ch == popped[tmp])
            {
                tmp++;
                if (!st.empty())
                {
                    while (!st.empty() && (st.top() == popped[tmp]))
                    {
                        st.pop();
                        tmp++;
                    }
                }
            }
            else
                st.push(ch);
        }
        return tmp == n2;
    }
};
int main() {
    return 0;
}